package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.DatInfo;
import com.ruoyi.system.domain.vo.DatCount;
import com.ruoyi.system.mapper.DatInfoMapper;
import com.ruoyi.system.service.IDatInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author wxd
 * @date 2024-08-01
 */
@Api(value = "焊接数据", tags = {"焊接数据"})
@RestController
@RequestMapping("/system/DatInfo")
public class DatInfoController extends BaseController {
    @Autowired
    private IDatInfoService datInfoService;
    @Autowired
    private DatInfoMapper datInfoMapper;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询分页列表")
    @GetMapping("/list")
    public TableDataInfo list(DatInfo datInfo) {
        startPage();
        List<DatInfo> list = datInfoService.selectDatInfoList(datInfo);
        DatCount datCount = datInfoMapper.datCountPage(datInfo);
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setCountData(datCount);
        return dataTable;
    }

    /**
     * 查询报警列表
     */
    @ApiOperation("产量统计")
    @GetMapping("/reportDat")
    public TableDataInfo reportDat(DatInfo datInfo) {
        startPage();
        List<DatCount> list = datInfoMapper.reportDat(datInfo);
        TableDataInfo dataTable = getDataTable(list);
        DatCount datCount = datInfoMapper.datCountPage(datInfo);
        dataTable.setCountData(datCount);
        return dataTable;
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询字段分组列表")
    @Anonymous
    @GetMapping("/fieldGroup")
    public List<String> fieldGroup(String fieldName) {
        return datInfoService.selectFieldGroup(fieldName);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DatInfo datInfo) {
        List<DatInfo> list = datInfoService.selectDatInfoList(datInfo);
        ExcelUtil<DatInfo> util = new ExcelUtil<DatInfo>(DatInfo.class);
        util.exportExcel(response, list, "焊接数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{DatID}")
    public AjaxResult getInfo(@PathVariable("DatID") Long DatID) {
        return success(datInfoService.selectDatInfoByDatID(DatID));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("新增")
    @Anonymous
    @PostMapping
    public AjaxResult add(@RequestBody DatInfo datInfo) {
        DatInfo old = datInfoService.selectOne(datInfo.getDatID(), datInfo.getDeviceId());
        if (old != null) {
            return AjaxResult.error("已存在相同数据");
        }
        return toAjax(datInfoService.insertDatInfo(datInfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@RequestBody DatInfo datInfo) {
        return toAjax(datInfoService.updateDatInfo(datInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("删除")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(datInfoMapper.deleteByIds(ids));
    }
}
